//获取应用实例
var app = getApp();

Page({

    data: {
        userInfo: {},
        orderlistnav: [{
          name: '我的租赁',
          img: './mine_img/zulin.png',
          status:'1'
        }, {
          name: '我的出租',
          img: './mine_img/chuzu.png',
          status: '2'
        }, {
          name: '便民订单',
          img: './mine_img/bianmin.png',
          status: '3'
        }],
        listnav: [
          {
            name: '我的收藏',
            img: './mine_img/shoucang.png',
            event: 'onConcern'
          }, {
            name: '收货地址',
            img: './mine_img/dizhi.png',
            event: 'onShouhuo'
          }, {
            name: '官方客服',
            img: './mine_img/kefu.png',
            event: 'showModal'
          }
        ]
    },
    //完善资料
    toUserinfo: function (e) {
      wx.navigateTo({
        url: '/pages/mine/userinfo/userinfo',
      })
    },
    //全部订单
    onAllOrder: function(e) {
      var o = e.currentTarget.dataset
      switch(o.status){
        case '1':
          var url = 'zulin'          
          break;
        case '2':
          var url = 'chuzu' 
          break;
        case '3':
          var url = 'bianmin' 
          break;
      }
      wx.navigateTo({
        url: '/pages/order/'+url
      })
    },
    // 弹窗显示
    showModal: function () {
      this.setData({
        showModal: !this.data.showModal
      })
    },
    //联系售后
    onShouhou: function(e) {
        wx.showModal({
            title: '我要投诉',
            content: '电话：0351-2983824',
            confirmText: '拨打电话',
            success: function(res) {
                if (res.confirm) {
                    wx.makePhoneCall({
                        phoneNumber: '0351-2983824',
                        success: function() {
                            console.log("拨打电话成功！")
                        },
                        fail: function() {
                            console.log("拨打电话失败！")
                        }
                    })
                } else if (res.cancel) {
                    console.log('用户点击取消')
                }
            }
        })

    },
    // 拨打电话
    call:function(e){
      var o = e.currentTarget.dataset;
      wx.makePhoneCall({
        phoneNumber: o.phone
      })
    },
    // 弹窗隐藏
    showModal:function(){
      this.setData({
        showModal:!this.data.showModal
      })
    },
    //我要分享
    onShare: function(res) {
        if (res.from === 'button') {
            // 来自页面内转发按钮
            console.log(res.target)
        }
        return {
            title: '宿达',
            path: '/pages/mine/mine',
            success: function(res) {
                // 转发成功
            },
            fail: function(res) {
                // 转发失败
            }
        }
    },

    //收获地址
    onShouhuo: function(e) {
        wx.navigateTo({
            url: '/pages/address/list/list',
        })
    },
    onConcern:function(e){
      wx.navigateTo({
        url: '/pages/mine/sc/goodslist',
      })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        console.log('onLoad')
        var that = this
            //调用应用实例的方法获取全局数据
        var userInfo = app.globalData.userInfo
        this.setData({
          userInfo: userInfo
        })
        app.getUserInfo(function(userInfo) {
            //更新数据
            console.log(userInfo.avatarUrl)
            that.setData({
                userInfo: userInfo
            })
        })
    },

})